package ar.edu.utn.frsf.tpae.a2012.g05.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import ar.edu.utn.frsf.tpae.a2012.g05.facade.HomeBankingFacade;
import ar.edu.utn.frsf.tpae.a2012.g05.service.ClienteService;
import ar.edu.utn.frsf.tpae.a2012.g05.service.CuentaService;
import ar.edu.utn.frsf.tpae.a2012.g05.service.MovimientoService;

/**
 * Clase de utilidad que provee acceso a instancias administradas por Spring.
 * 
 * @author TPAE
 */
public class ServiceLocator {

	private static ApplicationContext context;

	private static ApplicationContext getContext() {
		if (context == null) {
			synchronized (ServiceLocator.class) {
				if (context == null) {
					context = new ClassPathXmlApplicationContext(
							"classpath*:**/application-context.xml");
				}
			}
		}
		return context;
	}
	
	public static HomeBankingFacade getHomeBankingFacade() {
		return (HomeBankingFacade) getContext().getBean("homeBankingFacadeImpl");
	}

	public static ClienteService getClienteService() {
		return (ClienteService) getContext().getBean("clienteService");
	}
	
	public static CuentaService getCuentaService() {
		return (CuentaService) getContext().getBean("cuentaService");
	}

	public static MovimientoService getMovimientoService() {
		return (MovimientoService) getContext().getBean("movimientoService");
	}
}
